package com;

import java.util.List;

public class Page<T> {
    private int pageSize = 10;//每页记录数,可以用户自定义
    private int current = 1;//当前页，默认第1页//    sql起始点计算函数：(current - 1)*pageSize ->start
    private int count = 0;//select count(*) from tab ，总记录数
    private int totalPage = 0;//总页数
    private List<T> objList;
    private int start = 0;//查询起始点

    public Page(int current,int pageSize) {
        this.pageSize = pageSize;
        this.current = current;
        this.jiSuanStart();
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    /**
     * 获得起始点
     * @return
     */
    private void jiSuanStart(){
        this.start =  (this.current - 1)*this.pageSize;
    }


    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCurrent() {
        return current;
    }

    public void setCurrent(int current) {
        this.current = current;
    }

    public int getCount() {
        return count;
    }

    /**
     * 设置记录数，就能计算总页数
     * @param count
     */
    public void setCount(int count) {
        this.count = count;
        this.totalPage = this.count % this.pageSize == 0 ? this.count/this.pageSize : this.count/this.pageSize + 1;
        //分页查询起始点
        this.jiSuanStart();
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public List<T> getObjList() {
        return objList;
    }

    public void setObjList(List<T> objList) {
        this.objList = objList;
    }

    @Override
    public String toString() {
        return "Page{" +
                "pageSize=" + pageSize +
                ", current=" + current +
                ", count=" + count +
                ", totalPage=" + totalPage +
                ", objList=" + objList +
                ", start=" + start +
                '}';
    }
}
